<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <title>Document</title>
    </head>
    <body>
        <h2>1.在img标签上使用onerror事件,onerror加载的图片也失败的话会造成死循环</h2>
        <!-- <img src="http://imgtianqi.eastday.com/res/upload/ue/image/20171025/1508896339239073.png" onerror='this.src="http://imgtianqi.eastday.com/res/upload/ue/image/20171025/1508896339239073.png"' alt="图片" /> -->
        <h2>2.$("img").error(function(){this.src="默认图片地址"}),默认图片地址加载失败也容易造成死循环</h2>
        <h2>3.$("img").one('error',function(){this.src="默认图片地址"})，即使默认图片加载失败也不会造成死循环</h2>
        <img src="http://imgtianqi.eastday.com/res/upload/ue/image/20171025/1508896339239073.jpg" alt="图片" />
        <script src="http://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
        <script>
            // 2.$("img").error()
            // $("img").error(function(){
            //     this.src="http://imgtianqi.eastday.com/res/upload/ue/image/20171025/1508896339239073.png";
            // })
            // 3.$("img").one("error",function(){});
            $("img").one("error",function(){
                this.src="http://imgtianqi.eastday.com/res/upload/ue/image/20171025/1508896339239073.png";
            })
        </script>
    </body>
</html>